/**
 * 实名认证相关工具函数
 */

/**
 * 检查用户是否已实名认证
 * @returns {boolean} 是否已认证
 */
export function isUserVerified() {
  const verificationStatus = uni.getStorageSync('verificationStatus');
  return !!verificationStatus;
}

/**
 * 检查实名认证并提示用户
 * @param {string} action 需要认证的操作名称
 * @returns {Promise<boolean>} 是否已认证
 */
export function checkVerification(action = '此操作') {
  return new Promise((resolve) => {
    if (isUserVerified()) {
      resolve(true);
      return;
    }
    
    uni.showModal({
      title: '实名认证提醒',
      content: `${action}需要完成实名认证，请先到个人中心完成认证`,
      confirmText: '去认证',
      cancelText: '取消',
      success: (res) => {
        if (res.confirm) {
          uni.switchTab({
            url: '/pages/profile/profile'
          });
        }
        resolve(false);
      }
    });
  });
}

/**
 * 设置实名认证状态
 * @param {boolean} status 认证状态
 */
export function setVerificationStatus(status) {
  uni.setStorageSync('verificationStatus', status);
}

/**
 * 获取实名认证状态
 * @returns {boolean} 认证状态
 */
export function getVerificationStatus() {
  return uni.getStorageSync('verificationStatus') || false;
}

